rm update
[EroBeats.git] / Djinn and Tonic - Erobeats / Trainer.cpp
blob9150905ac0f284a2aa7659f5a8b1b6f30061414d
1 #include "Trainer.h"
3 #include "ScreenNames.h"
4 #include "RescourceKeys.h"
5 using namespace std::chrono;
6 Trainer::Trainer()
10 Trainer::Trainer(int* scrn, FileIO* fileIO, ResourceMaster* resourcePointer, int pattern)
12 rsc = resourcePointer;
13 screen = scrn;
14 rio = new RhythmIO(fileIO);
15 tTools = new TempoTools(rio);
16 font = new Fonts(0, rsc);
17 renderer = rsc->rendPtr;
19 outlineAnimation = new Animation(rsc->gameAnimations.at(WhiteBlueBG));
21 lightNumber = 0;
23 fadeOutMusic(500);
24 SDL_Delay(500);
26 countDownTime = 10;
27 countDownDuration = 300;
29 switch (pattern) {
30 case 11:
31 isPattern1_1 = true;
32 initializeBeats("Levels/T1");
33 break;
34 case 12:
35 isPattern1_2 = true;
36 initializeBeats("Levels/T2");
37 break;
40 createText();
42 int col1 = font->prcnt(0.1, 'x');
43 int col2 = font->prcnt(0.2, 'x');
44 int col3 = font->prcnt(0.3, 'x');
45 int col4 = font->prcnt(0.5, 'x');
47 goalRect = { col1, font->prcnt(0.1, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
48 subGoalRect = { col2, font->prcnt(0.15, 'y'), font->prcnt(0.05, 'x') , font->prcnt(0.05, 'y') };
49 levelRect = { col3, font->prcnt(0.2, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
51 nextRect = { col4, font->prcnt(0.3, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
52 startRect = { col4, font->prcnt(0.3, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
54 countDownRect = { col2, font->prcnt(0.3, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
56 aheadRect = { col3, font->prcnt(0.8, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
57 behindRect = { col1, font->prcnt(0.8, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
58 perfectRect = { col2, font->prcnt(0.8, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
60 light1Rect = { col2, font->prcnt(0.7, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
61 light2Rect = { col3, font->prcnt(0.7, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
62 light3Rect = { col4, font->prcnt(0.7, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
63 light4Rect = { col4, font->prcnt(0.7, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
66 mouseRect = { col4, font->prcnt(0.1, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
67 mouseRightRect = { col4, font->prcnt(0.5, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
68 mouseLeftRect = { col4, font->prcnt(0.5, 'y'), font->prcnt(0.1, 'x') , font->prcnt(0.1, 'y') };
70 startMusic(-1, 0);
71 gameLoop();
75 Trainer::~Trainer()
77 delete rio;
78 delete tTools;
79 delete font;
80 destroyText();
83 void Trainer::createText() {
84 if (isPattern1_1) {
85 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(GoalText), 2);
86 goalText = font->getTexture();
87 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(SubGoalText), 2);
88 subGoalText = font->getTexture();
89 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(Animation1Text), 2);
90 levelText = font->getTexture();
92 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(NextText), 2);
93 nextText = font->getTexture();
95 font->loadFont(SDL_Color{ 0,0,0,0 }, to_string(countDownTime), 2);
96 countDownText = font->getTexture();
99 else if (isPattern1_2) {
100 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(GoalText), 2);
101 goalText = font->getTexture();
102 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(SubGoalText), 2);
103 subGoalText = font->getTexture();
104 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(Animation1Text), 2);
105 levelText = font->getTexture();
107 font->loadFont(SDL_Color{ 0,0,0,0 }, rsc->gameText.at(StartText), 2);
108 startText = font->getTexture();
110 font->loadFont(SDL_Color{ 0,0,0,0 }, to_string(countDownTime), 2);
111 countDownText = font->getTexture();
115 void Trainer::destroyText() {
116 SDL_DestroyTexture(goalText);
117 SDL_DestroyTexture(subGoalText);
118 SDL_DestroyTexture(levelText);
119 SDL_DestroyTexture(startText);
120 SDL_DestroyTexture(nextText);
121 SDL_DestroyTexture(countDownText);
124 void Trainer::loadPattern() {
125 if (isPattern1_1) {
126 initializeBeats("Levels/T1");
127 startMusic(-1, 0);
129 else if (isPattern1_2) {
130 initializeBeats("Levels/T2");
131 startMusic(-1, 0);
135 void Trainer::update() {
136 if (!tTools->done) {
137 if (isPattern1_2 && x > startRect.x && x < startRect.x + startRect.w && y > startRect.y && y < startRect.y + startRect.h) {
138 hoverStart = true;
140 else {
141 hoverStart = false;
143 if (hoverStart && mouseClicked && !(playedOnce1 || playedOnce2)) {
144 start = true;
146 if (start && isPattern1_2) {
147 destroyText();
148 running = false;
151 if (isPattern1_1 && x > nextRect.x && x < nextRect.x + nextRect.w && y > nextRect.y && y < nextRect.y + nextRect.h) {
152 hoverNext = true;
154 else {
155 hoverNext = false;
157 if (hoverNext && mouseClicked && !(playedOnce1 || playedOnce2)) {
158 next = true;
160 if (next && isPattern1_1) {
161 isPattern1_1 = false;
162 isPattern1_2 = true;
163 next = false;
164 destroyText();
165 createText();
166 loadPattern();
169 tTools->countDown(&countDownTime, countDownDuration);
170 if (countDownTime < 0) {
171 exit(1);
173 tTools->proccessDataSlow();
174 tTools->moveTicker();
175 playCue[0] = tTools->autoPlay(10);
176 playCue[1] = tTools->autoPlay(20);
177 playCue[1] = tTools->autoPlay(30);
179 if (isPattern1_1) {
180 if (playCue[0] == 1) {
181 if (light2Switch) {
182 light2Switch = false;
184 else {
185 if (light1Switch)
186 light2Switch = true;
187 light1Switch = true;
188 light3Switch = false;
190 perfect = false;
191 behind = false;
192 ahead = false;
196 if (leftMBSwitch && playCue[0] == 1) {
197 leftMBSwitch = false;
199 else if (playCue[1] == 1) {
200 leftMBSwitch = true;
202 if (rightMBSwitch && playCue[2] == 1) {
203 rightMBSwitch = false;
205 else if (playCue[2]== 1) {
206 rightMBSwitch = true;
210 playSound1 = tTools->clickAccuracy(1);
211 std::cout << playSound1 << "\n";
212 if (playSound1 == 0) {
213 perfect = true;
214 behind = false;
215 ahead = false;
217 else if (playSound1 == 1) {
218 behind = true;
219 ahead = false;
220 perfect = false;
222 else if (playSound1 == -1) {
223 ahead = true;
224 perfect = false;
225 behind = false;
229 if (leftMouseClicked && !playedOnceL) {
230 if (isPattern1_1) {
231 playSound[0] = tTools->clickAccuracy(1, true);
232 if (playSound[0] == 0) {
233 light1Switch = false;
234 light2Switch = false;
235 light3Switch = true;
236 perfect = true;
237 behind = false;
238 ahead = false;
241 if (playSound[0] == 1) {
242 behind = true;
243 ahead = false;
244 perfect = false;
246 else if (playSound[0] == -1) {
247 ahead = true;
248 perfect = false;
249 behind = false;
253 else {
254 running = false;
258 void Trainer::play() {
259 if (playCue[0] == 1 ) {
260 rsc->sptr->playSFX(2);
261 playCue[0] = 0;
263 if (playSound[0] == 0 && !playedOnceL) {
264 rsc->sptr->playSFX(3);
265 playSound[0] = 9;
267 else if (playSound[0] == 1 && !playedOnceL) {
268 rsc->sptr->playSFX(1);
269 playSound[0] = 9;
271 else if (playSound[0] == -1 && !playedOnceL) {
272 rsc->sptr->playSFX(1);
273 playSound[0] = 9;
277 void Trainer::render() {
278 SDL_RenderClear(renderer);
280 if (hoverStart || hoverNext) {
281 SDL_RenderCopy(renderer, outlineAnimation->itterateAnimation(30), NULL, &startRect);
284 SDL_RenderCopy(renderer, goalText, NULL, &goalRect);
285 SDL_RenderCopy(renderer, subGoalText, NULL, &subGoalRect);
286 SDL_RenderCopy(renderer, levelText, NULL, &levelRect);
287 SDL_RenderCopy(renderer, startText, NULL, &startRect);
288 SDL_RenderCopy(renderer, nextText, NULL, &nextRect);
290 stringstream stream;
291 stream << fixed << setprecision(3) << countDownTime;
292 string formattedCounter = stream.str();
294 font->loadFont(SDL_Color{ 0,0,0,0 }, formattedCounter, 2);
295 countDownText = font->getTexture();
297 SDL_RenderCopy(renderer, countDownText, NULL, &countDownRect);
299 SDL_DestroyTexture(countDownText);
301 //generate lights
302 SDL_RenderCopy(renderer, rsc->gameGraphics.at(RedDark), NULL, &light1Rect);
303 SDL_RenderCopy(renderer, rsc->gameGraphics.at(RedDark), NULL, &light2Rect);
304 SDL_RenderCopy(renderer, rsc->gameGraphics.at(GreenDark), NULL, &light3Rect);
306 if (light1Switch) {
307 SDL_RenderCopy(renderer, rsc->gameGraphics.at(RedBright), NULL, &light1Rect);
309 if (light2Switch) {
310 SDL_RenderCopy(renderer, rsc->gameGraphics.at(RedBright), NULL, &light2Rect);
312 if (light3Switch) {
313 SDL_RenderCopy(renderer, rsc->gameGraphics.at(GreenBright), NULL, &light3Rect);
316 //generate mouse
317 SDL_RenderCopy(renderer, rsc->gameGraphics.at(Mouse), NULL, &mouseRect);
319 if (leftMBSwitch) {
320 SDL_RenderCopy(renderer, rsc->gameGraphics.at(MouseL), NULL, &mouseLeftRect);
322 if (rightMBSwitch) {
323 SDL_RenderCopy(renderer, rsc->gameGraphics.at(MouseR), NULL, &mouseRightRect);
326 //gen arrows
327 if (behind) {
328 SDL_RenderCopy(renderer, rsc->gameGraphics.at(LArrow), NULL, &aheadRect);
330 else if (ahead) {
331 SDL_RenderCopy(renderer, rsc->gameGraphics.at(RArrow), NULL, &behindRect);
333 else if(perfect) {
334 SDL_RenderCopy(renderer, rsc->gameGraphics.at(Circle), NULL, &perfectRect);
337 SDL_RenderPresent(renderer);